//-
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

include /app/helpers/jade/mixins

-var form = 'store'
-var model = 'backupItem'
-var keyFields = `${model}.keyFields`
-var valueFields = `${model}.valueFields`

mixin list-db-field-edit({ items, itemName, itemsName })
    list-editable(
        ng-model=items
        ng-model-options='{allowInvalid: true}'
        ui-validate=`{
            dbFieldUnique: '$ctrl.Models.storeKeyDBFieldsUnique($value)'
        }`
        ui-validate-watch=`"${items}"`
        ui-validate-watch-object-equality='true'
    )&attributes(attributes)
        list-editable-item-view
            | {{ $item.databaseFieldName }} / {{ $item.databaseFieldType }} / {{ $item.javaFieldName }} / {{ $item.javaFieldType }}

        list-editable-item-edit
            .pc-form-grid-row
                .pc-form-grid-col-30(divider='/')
                    +form-field__text({
                        label: 'DB name:',
                        model: '$item.databaseFieldName',
                        name: '"databaseFieldName"',
                        required: true,
                        placeholder: 'Enter DB name'
                    })(
                        ng-model-options='{allowInvalid: true}'
                        ignite-auto-focus
                        ignite-unique=items
                        ignite-unique-property='databaseFieldName'
                    )
                        +form-field__error({ error: 'igniteUnique', message: 'DB name should be unique' })
                .pc-form-grid-col-30
                    +form-field__dropdown({
                        label: 'DB type:',
                        model:'$item.databaseFieldType',
                        name: '"databaseFieldType"',
                        required: 'true',
                        placeholder: 'Choose DB type',
                        options: 'supportedJdbcTypes'
                    })
                .pc-form-grid-col-30(divider='/')
                    +form-field__text({
                        label: 'Java name:',
                        model: '$item.javaFieldName',
                        name: '"javaFieldName"',
                        required: true,
                        placeholder: 'Enter Java name'
                    })(
                        ng-model-options='{allowInvalid: true}'
                        ignite-unique=items
                        ignite-unique-property='javaFieldName'
                    )
                        +form-field__error({ error: 'igniteUnique', message: 'Java name should be unique' })
                .pc-form-grid-col-30
                    +form-field__dropdown({
                        label: 'Java type:',
                        model: '$item.javaFieldType',
                        name: '"javaFieldType"',
                        required: 'true',
                        placeholder: 'Choose Java type',
                        options: 'supportedJavaTypes'
                    })

        list-editable-no-items
            list-editable-add-item-button(
                add-item=`$editLast((${items} = ${items} || []).push({}))`
                label-single=itemName
                label-multiple=itemsName
            )

panel-collapsible(ng-form=form on-open=`ui.loadPanel('${form}')`)
    panel-title#store-title Domain model for cache store
    panel-description
        | Domain model properties for binding database with cache via POJO cache store.
        a.link-success(href="https://apacheignite.readme.io/docs/3rd-party-store" target="_blank") More info
    panel-content.pca-form-row(ng-if=`ui.isPanelLoaded('${form}')`)
        .pca-form-column-6.pc-form-grid-row
            .pc-form-grid-col-30
                +form-field__text({
                    label: 'Database schema:',
                    model: model + '.databaseSchema',
                    name: '"databaseSchema"',
                    placeholder: 'Input DB schema name',
                    tip: 'Schema name in database'
                })
            .pc-form-grid-col-30
                +form-field__text({
                    label: 'Database table:',
                    model: model + '.databaseTable',
                    name: '"databaseTable"',
                    placeholder: 'Input DB table name',
                    tip: 'Table name in database'
                })
            .pc-form-grid-col-60
                .ignite-form-field
                    +form-field__label({ label: 'Key fields:', name: '"keyFields"' })
                        +form-field__tooltip({ title: `Collection of key fields descriptions for CacheJdbcPojoStore` })

                    +list-db-field-edit({
                        items: keyFields,
                        itemName: 'key field',
                        itemsName: 'key fields'
                    })(name='keyFields')

                    .form-field__errors(
                        ng-messages=`store.keyFields.$error`
                        ng-show=`store.keyFields.$invalid`
                    )
                        +form-field__error({ error: 'dbFieldUnique', message: 'Each key field DB name and Java name should be unique' })

            .pc-form-grid-col-60
                .ignite-form-field
                    +form-field__label({ label: 'Value fields:', name: '"valueFields"' })
                        +form-field__tooltip({ title: `Collection of value fields descriptions for CacheJdbcPojoStore` })

                    +list-db-field-edit({
                        items: valueFields,
                        itemName: 'value field',
                        itemsName: 'value fields'
                    })(name='valueFields')

                    .form-field__errors(
                        ng-messages=`store.valueFields.$error`
                        ng-show=`store.valueFields.$invalid`
                    )
                        +form-field__error({ error: 'dbFieldUnique', message: 'Each value field DB name and Java name should be unique' })

        .pca-form-column-6
            +preview-xml-java(model, 'domainStore')

